<?php

namespace Admin\Controller; //当前命名空间跟文件目录一样
use Common\Common\CommonController;  //继承公共控制器类，时刻检测管理员身份
class OrderController extends CommonController
{

	//显示所有订单
	public function showList()
	{ //检查管理员登录信息
		$this->checkAdmin();
		$modelOrder = M('Order');
		//接收传递订单状态查询值os
		$shipping_status = I('os') != null ? I('os') : '';
		$shipping_status = ($shipping_status == 1) ? '待发货' : $shipping_status;
		$shipping_status = ($shipping_status == 2) ? '待收货' : $shipping_status;
		$shipping_status = ($shipping_status == 3) ? '已收货' : $shipping_status;

		if (!empty($shipping_status)) {
			$where = array('shipping_status' => $shipping_status);
			//实例化订单模型，查询目前用户具体物流状态订单
			$orderInfo = $modelOrder->where($where)->select();
			//将订单数据返回到视图
			$this->assign("orderInfo", $orderInfo);
		} else {
			// print_r($where);die;
			//模型类对象获取当前用户的全部订单信息
			$orderInfo = $modelOrder->select();
			//将订单数据返回到视图
			$this->assign("orderInfo", $orderInfo);
		}

		$this->display();
	}


	//根据订单号查询
	public function query()
	{
		//检查管理员登录信息
		$this->checkAdmin();
		$order_id = I('order_id'); //获取订单编号
		$model = M('order');
		if ($orderInfo = $model->where(array('order_id' => $order_id))->select()) //如果订单号存在
		{
			$this->assign('orderInfo', $orderInfo);
		}
		$this->display();
	}

	//订单物流状态修改
	public function update()
	{
		//检查管理员登录信息
		$this->checkAdmin();
		//得到目标商品编号
		$order_id = I('oi');
		$model = M('order');
		if (IS_POST) {
			$shipping_status = I('shipping_status');
			$data = (array('shipping_status' => $shipping_status));
			if ($model->where(array("order_id" => $order_id))->save($data)) {
				$this->success("修改订单物流状态成功！！", U('?m=admin&c=order&a=showList'));
				die;
			}
			$this->error("修改订单物流状态失败！！！！");
		}
		if ($orderInfo = $model->where(array('order_id' => $order_id))->select()) //如果订单号存在
		{
			$this->assign('orderInfo', $orderInfo);
		}
		$this->display();
	}

	//订单删除
	public function deleteOrder()
	{
		//检查管理员登录信息
		$this->checkAdmin();
		$order_id = I('oi');
		$model = M('order');
		if ($model->where(array('order_id' => $order_id))->delete()) {
			$this->success("订单删除成功");
			die;
		}
		$this->error("订单删除失败！！");
	}
}
